/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import { getList, createExport } from "@/services/inventoryManagement";
import { message } from "antd";

export default {
  namespace: "inventory",

  state: {},

  effects: {
    // 获取列表
    *getList({ payload, __dva_resolve, __dva_reject }, { call }) {
      const response = yield call(getList, payload);

      if (!response) return;
      const { code, data = {}, msg } = response;
      const { list, total, page } = data;

      if (code == 0) {
        __dva_resolve({
          list,
          pagination: {
            total,
            current: page,
            pageSize: 20,
            showQuickJumper: false,
            showSizeChanger: false,
          },
        });
      } else {
        message.error(msg);
        __dva_reject();
      }
    },
    // 获取列表
    *createExport({ payload, __dva_resolve, __dva_reject }, { call }) {
      const response = yield call(createExport, payload);

      if (!response) return;
      const { code, msg } = response;

      if (code == 0) {
        __dva_resolve(msg);
      } else {
        __dva_reject(msg);
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
